package com.wc.alorithm_blue_bridge._数据结构.线段树.龙骑士军团;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/6/30 1:00
 * @description https://www.lanqiao.cn/problems/19680/learning/?contest_id=193
 */
public class Main {
    /**
     * 前缀和 + 线段树
     * 思路
     * [a, b] 之间找最小的 也就是 [a - 1, b - 1] 之间找最小值
     * [c, d] 之间找最大的 也就是 [c, d]之间找最大值
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010, M = N << 2;
    static long[] maxSum = new long[M];
    static long[] minSum = new long[M];
    static long[] s = new long[N];
    static int n, q;

    public static void main(String[] args) {
        n = sc.nextInt();
        q = sc.nextInt();
        for (int i = 1; i <= n + 1; i++) s[i] = s[i - 1] + sc.nextInt();
        build(1, 0, n);
        while (q-- > 0) {
            int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt();
            out.println(queryMax(1, 0, n, c, d) - queryMin(1, 0, n, a - 1, b - 1));
        }
        out.flush();
    }

    static void pushUp(int u) {
        maxSum[u] = Math.max(maxSum[u << 1], maxSum[u << 1 | 1]);
        minSum[u] = Math.min(minSum[u << 1], minSum[u << 1 | 1]);
    }


    static void build(int u, int l, int r) {
        if (l == r) {
            maxSum[u] = minSum[u] = s[l];
            return;
        }
        int mid = l + r >> 1;
        build(u << 1, l, mid);
        build(u << 1 | 1, mid + 1, r);
        pushUp(u);
    }

    static long queryMax(int u, int l, int r, int ql, int qr) {
        if (l == ql && r == qr) {
            return maxSum[u];
        }
        int mid = l + r >> 1;
        if (mid >= qr) return queryMax(u << 1, l, mid, ql, qr);
        else if (mid < ql) return queryMax(u << 1 | 1, mid + 1, r, ql, qr);
        return Math.max(queryMax(u << 1, l, mid, ql, mid), queryMax(u << 1 | 1, mid + 1, r, mid + 1, qr));
    }

    static long queryMin(int u, int l, int r, int ql, int qr){
        if (l == ql && r == qr) {
            return minSum[u];
        }
        int mid = l + r >> 1;
        if (mid >= qr) return queryMin(u << 1, l, mid, ql, qr);
        else if (mid < ql) return queryMin(u << 1 | 1, mid + 1, r, ql, qr);
        return Math.min(queryMin(u << 1, l, mid, ql, mid), queryMin(u << 1 | 1, mid + 1, r, mid + 1, qr));
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
